package ch05.d2;

import org.junit.Test;

import java.util.Arrays;

public class ArrayTest {
    @Test
    public void testNew(){
        String[] b=new String[12];
        String[][] a=new String[8][6];
        a[0][0]="电风扇";
        a[0][1]="李晨浩";
        a[1][5]="郭亚川";
        a[5][2]="柴源";
        a[2][3]="张静";
        a[2][5]="王佳琪";
        a[7][4]="李康帅";
        a[5][3]="许铎";
        a[0][4]="刘畅";

        for (int i = 0; i < a.length; i++) {//a.length 3
            System.out.println(Arrays.toString( a[i]) );
        }

        System.out.println(a);


    }

    @Test
    public void testNew2(){
        int[][][] a=new int[3][4][5];

        for (int i = 0; i < a.length; i++) {
            for (int i1 = 0; i1 < a[i].length; i1++) {
                for (int i2 = 0; i2 < a[i][i1].length; i2++) {
                    System.out.print(a[i][i1][i2]+" ");
                }
                System.out.println();
            }
            System.out.println();
        }
    }

    public int rich(int[][] moneys){
        int[] list=new int[moneys.length];
        for (int i = 0; i < moneys.length; i++) {
            for (int j = 0; j < moneys[i].length; j++) {
                list[i]+=moneys[i][j];
            }
        }
        Arrays.sort(list);
        return list[list.length-1];
    }

    @Test
    public void testRich(){
        int[][] a={{1,2,3},{2,3,4,5,6},{3,4,5,5,6,7}};
        rich(a);
    }


    @Test
    public void testStudent(){
        Student[] a=new Student[6];
//        刘海东	21	87
//        王梦月	22	85
//        韩少卿	20	89
//        李岩华	23	84
//        王正文	21	85
        a[0]=new Student("刘海东",21,87);
        a[1]=new Student("王梦月",22,85);
        a[2]=new Student("韩少卿",20,89);
        a[3]=new Student("李岩华",23,84);
        a[4]=new Student("王正文",21,85);
        a[5]=null;

        for (int i = 0; i < a.length; i++) {
            // 学生对象.name属性      姓名

            if(a[i]!=null && a[i].name.equals("韩少卿")){
                System.out.println(a[i]);
            }
        }
    }

    @Test
    public void testArray2(){
        int[][] a={{1,2,3},{4,5,6}};
        int[][] b=new int[a[0].length][a.length];

        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                b[j][i]=a[i][j];
            }
        }

        for (int i = 0; i < b.length; i++) {
            for (int i1 = 0; i1 < b[i].length; i1++) {
                System.out.print(b[i][i1]);
            }
            System.out.println();
        }
    }

}
